package com.yusong.test;

import com.yusong.test.aop.Subject;
import com.yusong.test.aspectJ.spring.TestBean;
import com.yusong.test.beanPost.MyJavaBean;
import com.yusong.test.factoryBean.Student;
import com.yusong.test.listener.EmailBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 * Created by yusong on 2017/2/14.
 */
public class Main {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("aop/applicationContext.xml");
        Subject proxy= (Subject) context.getBean("requestAOP");
        proxy.request("yusong");
        //proxy.request("hello");

        TestBean testBean = (TestBean)context.getBean("testBean");
        testBean.test();

        Student stuFactory1 = (Student) context.getBean("stuFactory");
        Student stuFactory2 = (Student) context.getBean("stuFactory");
        System.out.println(stuFactory1 == stuFactory2);
        //需要返回FactoryBean实例
        System.out.println(context.getBean("&stuFactory").getClass());

        EmailBean email = (EmailBean) context.getBean("emailer");
        email.sendEmail("black@list.org");


        //BeanPostProcessor
        MyJavaBean bean = (MyJavaBean) context.getBean("myJavaBean");
        System.out.println("===============下面输出结果============");
        System.out.println("描述：" + bean.getDesc());
        System.out.println("备注：" + bean.getRemark());

    }
}
